package com.huluobo.a2207kotlindouyin.live

import androidx.lifecycle.MutableLiveData
import com.huluobo.base.bean.GiftBean
import com.huluobo.base.bean.Money
import com.huluobo.base.db.DouYinDatabase
import com.huluobo.base.mvvm.BaseViewModel
import com.huluobo.base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import okhttp3.RequestBody
import javax.inject.Inject

/**
 *  Created by LC on 2024/11/30.
 */
@HiltViewModel
class LiveViewModel @Inject constructor(
    val apiService: ApiService,
    val db: DouYinDatabase
) : BaseViewModel() {
    val followAuthSuccess by lazy { MutableLiveData<String>() }
    fun followAuth(body: RequestBody) {
        executeNetwork(
            { apiService.followAuth(body) },
            followAuthSuccess::postValue
        )
    }

    val cancelFollowSuccess by lazy { MutableLiveData<String>() }
    fun cancelFollow(body: RequestBody) {
        executeNetwork(
            { apiService.cancelFollow(body) },
            cancelFollowSuccess::postValue
        )
    }

    val getGiftSuccess by lazy { MutableLiveData<List<GiftBean>>() }
    fun getGift() {
        executeNetwork(
            { apiService.getGift() },
            getGiftSuccess::postValue
        )
    }

    val queryMoneySuccess by lazy { MutableLiveData<Money>() }
    fun queryUserMoney(username: String) {
        executeDb(
            { db.getMoneyDao().queryMoneyByName(username) },
            queryMoneySuccess::postValue
        )
    }

    val updateMoneySuccess by lazy { MutableLiveData<String>() }
    fun updateMoney(money: Money) {
        executeDb(
            {
                db.getMoneyDao().updateMoney(money)
                "更新余额成功"
            },
            updateMoneySuccess::postValue
        )
    }
}